package com.gec.hawaste.controller;


import com.gec.hawaste.entity.SysOffice;
import com.gec.hawaste.service.ISysOfficeService;
import com.gec.hawaste.utils.PageInfo;
import com.gec.hawaste.utils.ResultBean;
import com.gec.hawaste.vo.SysOfficeDo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 机构表 前端控制器
 * </p>
 *
 * @author chenxys
 * @since 2022-07-01
 */
@Slf4j
@RestController
@RequestMapping("/manager/office")
public class SysOfficeController {
    @Autowired
    private ISysOfficeService officeService;

    /**
     * 查询所有的机构
     * @author chenxys
     * @return com.gec.hawaste.utils.ResultBean<com.gec.hawaste.entity.SysOffice>
     */
    @GetMapping("/selectAll")
    public ResultBean<SysOffice> selectAll(){
        List<SysOffice> list = officeService.list();
        return ResultBean.ok(list);
    }

    /**
     * 分页查询
     * @author chenxys
     * @param current 当前页
     * @param size 每页显示条数
     * @return com.gec.hawaste.utils.ResultBean<com.gec.hawaste.utils.PageInfo>
     */
    @GetMapping("/select")
    public ResultBean<PageInfo> select(Long current,Long size){
        PageInfo<SysOfficeDo> pageInfo = new PageInfo<>(current,size);
        pageInfo = (PageInfo<SysOfficeDo>) officeService.selectByCondition(pageInfo);
        pageInfo.setNavigatePage();
        return ResultBean.ok(pageInfo);
    }

    /**
     * 根据ID查询
     * @author chenxys
     * @param id 机构ID
     * @return com.gec.hawaste.utils.ResultBean<com.gec.hawaste.entity.SysOffice>
     */
    @GetMapping("/selectOne")
    public ResultBean<SysOfficeDo> selectOne(Long id){
        SysOfficeDo officeDo = officeService.selectByOfficeId(id);
        log.info("传入ID:{}",id);
        return ResultBean.ok(officeDo);
    }
}
